package com.mrogrape.notepad.activity.action.item;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;

import com.mrogrape.notepad.activity.MainFrame;
import com.mrogrape.notepad.data.ViewContext;
import com.mrogrape.notepad.ui.editor.TextEditor;


public class FindAndReplaceMenuItemAction extends AbstractAction{

	/** serialVersionUID */
	private static final long serialVersionUID = -1L;

	public FindAndReplaceMenuItemAction(MainFrame frame){

		this.frame = frame;
		super.putValue(Action.NAME, "Find And Replace");
		super.putValue(Action.SHORT_DESCRIPTION, "Find And Replace in Text Editor.");
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {

		ViewContext.getFindAndReplaceDialog().setVisible(true);
		TextEditor editor = this.frame.getCurrentTextEditor();
		if(editor != null){
			
			ViewContext.getFindAndReplaceDialog().setFindContent(editor.getSelectedText());
		}
	}

	private MainFrame frame;
}
